﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TelnetRouterApplication.Model
{
    public class VLAN
    {
        private string _name;
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        private string _number;
        public string Number
        {
            get { return _number; }
            set { _number = value; }
        }

        public VLAN() : this("", "") { }

        public VLAN(string name, string number)
        {
            Name = name;
            Number = number;
        }

        public static List<VLAN> GetListVLAN(List<string> messages)
        {
            List<VLAN> listVLAN = new List<VLAN>();

            for (int i = 0; i < messages.Count; i++)
            {
                if (messages[i].Contains("VLAN ISL"))
                {
                    string[] parameters = messages[i].Split(' ');

                    string number = parameters[parameters.Length - 1];

                    parameters = messages[i+1].Split(' ');

                    string name = parameters[parameters.Length - 1];

                    VLAN vlan = new VLAN(name, number);
                    listVLAN.Add(vlan);
                }
            }

            return listVLAN;
        }

        public override string ToString()
        {
            return Name+"@"+Number;
        }

        public override bool Equals(object obj)
        {
            if (obj is VLAN)
            {
                VLAN vlan = (VLAN) obj;
                return vlan.Name.Equals(Name) && vlan.Number.Equals(Number);
            }
            return false;
        }
    }
}
